/*
 * Copyright (c) 2012 free soft workgroup
 * All rights reserved
 *
 */
#ifndef UTILS_H_
#define UTILS_H_

#include "stdnet.h"
#include "tinyxml.h"
/*
*
*utils function
*/
class utils
{
public:
        utils(void);
        ~utils(void);
public:
        /*
        *
        *create crc16 by key
        */
        static unsigned short int crc16_has_key(unsigned char * key,size_t len);
        /*
        *
        *create crc32 by key
        */
        static unsigned int crc32_has_key(unsigned char * key,size_t len);
        /*
        *
        *utf8 decode
        */
        static unsigned int utf8_decode(ubyte **p, size_t n);

        /*
        * base64 encode
        */
        static size_t encode_base64(ubyte *dst,size_t dst_len, ubyte *src,size_t src_len);
        /*
        * b64_encode: Stolen from VLC's http.c.
        * Simplified by Michael.
        * Fixed edge cases and made it work from data (vs. strings) by Ryan.
        **/
        static char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
        /*
        *  base64 decode
        */
        static size_t decode_base64(ubyte *dst,size_t dst_len, ubyte *src,size_t src_len);

        /*
        *net bytes read
        */
        static unsigned int read_8(unsigned char const* buffer);
        static uint16_t read_16(unsigned char const* buffer);
        static unsigned int read_24(unsigned char const* buffer);
        static uint32_t read_32(unsigned char const* buffer);
        static uint64_t read_64(unsigned char const* buffer);
        /*
        *net byteswrite
        */
        static unsigned char* write_8(unsigned char* buffer, unsigned char v);
        static unsigned char* write_16(unsigned char* buffer, unsigned int v);
        static unsigned char* write_24(unsigned char* buffer, unsigned int v);
        static unsigned char* write_32(unsigned char* buffer, uint32_t v);
        static unsigned char* write_64(unsigned char* buffer, uint64_t v);
        /*
        *hexa trasform
        */
        static void hexa(char *s, ubyte * p_data, int i_data);
        static int hex_to_data(uint8_t *data, const char *p);
        /*
        *getrand
        */
        static int getrand(void);
        /*
        *url decode
        */
        static size_t url_decode(ubyte *dst,size_t dst_len, ubyte *src,size_t src_len);

private:

};

#endif //UTILS_H_
